﻿Imports System.Globalization
Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client


Partial Public Class SubmitFeatureRequest

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        DisplayVersion()
        DisplayServers()
    End Sub

#Region " routed events "



    Public Custom Event ServerButtonClick As RoutedEventHandler

        AddHandler(ByVal value As RoutedEventHandler)
            Me.AddHandler(ServerButtonClickEvent, value)
        End AddHandler

        RemoveHandler(ByVal value As RoutedEventHandler)
            Me.RemoveHandler(ServerButtonClickEvent, value)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
            Me.RaiseEvent(e)
        End RaiseEvent
    End Event

    Public Shared ReadOnly ServerButtonClickEvent As RoutedEvent = _
                      EventManager.RegisterRoutedEvent("ServerButtonClick", _
                      RoutingStrategy.Bubble, _
                      GetType(RoutedEventHandler), GetType(Welcome))



#End Region


    ''' <summary>
    ''' Display the application version.
    ''' </summary>
    Private Sub DisplayVersion()
        Dim Version As Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
        VersionLabel.Content = VersionLabel.Content.ToString & String.Format(CultureInfo.CurrentCulture, "{0}.{1}.{2}", Version.Major, Version.Minor, Version.Build)
    End Sub

    ''' <summary>
    ''' Display a list of team Servers.
    ''' </summary>
    Private Sub DisplayServers()

        For Each svr As TeamFoundationServer In RegisteredServers.GetServers
            Dim serverButton As Button = New Button()
            serverButton.Content = svr.Name
            serverButton.Command = HierarchicalDisplay.ChangeTeamServerCommand
            serverButton.CommandParameter = svr
            serverButton.Style = CType(FindResource("WelcomeButtonStyle"), Style)
            'AddHandler serverButton.Click, AddressOf ServerButton_Click
            ServersStackPanel.Children.Add(serverButton)
        Next

    End Sub

    Private Sub ServerButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        'Dim serverButton As Button = sender
        'MessageBox.Text = ""
        'Dim tfs As TeamFoundationServer = serverButton.CommandParameter
        'If tfs.HasAuthenticated Then
        '    [RaiseEvent](New RoutedEventArgs(ServerButtonClickEvent, sender))
        'Else
        '    Try
        '        tfs.Authenticate()
        '        [RaiseEvent](New RoutedEventArgs(ServerButtonClickEvent, sender))
        '    Catch ex As Exception
        '        MessageBox.Text = ex.Message
        '    End Try
        'End If


    End Sub


End Class
